package com.imooc.reader.management.dto;

import lombok.Data;

import java.util.LinkedHashMap;
import java.util.Map;

@Data
public class ResponseDTO {
    private String code;
    private String message;
    private Map<String, Object> data = new LinkedHashMap<>();

    public ResponseDTO() {
        this.code = "0";
        this.message = "success";
    }

    public ResponseDTO(String code, String message) {
        this.code = code;
        this.message = message;
    }

    /**
     * 发生异常时上报异常信息
     * @param e
     */
    public ResponseDTO(Exception e) {
        this.code = e.getClass().getSimpleName();
        this.message = e.getMessage();
    }

    public ResponseDTO put(String key, Object val) {
        this.data.put(key, val);
        return this;
    }
}
